﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;
using Infragistics.Win.UltraWinGrid;
using WHC.OrderWater.Commons;
using WHC.Pager.Entity;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using Maticsoft.DBUtility;

namespace CKNetFrameWork
{
    public partial class Frm_ClassPrdSchdDetail : DockContent
    {
        private TrainingDB.BLL.CK_SchdDetail m_bllCK_SchdDetail = new TrainingDB.BLL.CK_SchdDetail();
        private TrainingDB.BLL.CK_SchoolTab m_bllCK_SchoolTab = new TrainingDB.BLL.CK_SchoolTab();


        private TrainingDB.BLL.CK_TeacherTab m_bllCK_TeacherTab = new TrainingDB.BLL.CK_TeacherTab();
        private TrainingDB.BLL.CK_CourseTab m_bllCK_CourseTab = new TrainingDB.BLL.CK_CourseTab();
        private TrainingDB.BLL.CK_ClassRoomExTab m_bllCK_ClassRoomExTab = new TrainingDB.BLL.CK_ClassRoomExTab();
        private TrainingDB.BLL.CK_ClassTab m_bllCK_ClassTab = new TrainingDB.BLL.CK_ClassTab();
        private TrainingDB.BLL.CK_TimeSegTab m_bllCK_TimeSegTab = new TrainingDB.BLL.CK_TimeSegTab();


        private int m_nDelIndex = -1;
        private bool m_bInsertFlag = false;
        private Dictionary<string, string> m_dicColName2AliasName = new Dictionary<string, string>();
        private Dictionary<string, string> m_dicColAliasName2Name = new Dictionary<string, string>();
        private string m_filter = "";

        public Frm_ClassPrdSchdDetail()
        {
            InitializeComponent();
        }


        private void ShowAllRecordInDataGridView(string strWhere)
        {
            BindData(strWhere);
        }

        private void buttonShowAll_Click(object sender, EventArgs e)
        {
            m_filter = "";
            ShowAllRecordInDataGridView(m_filter);
        }
        private void InitColumnWidth()
        {

            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                ultraGrid1.DisplayLayout.Bands[0].Columns[m_dicColName2AliasName[strTemp]].Width = Frm_Main.m_nDfuColWidth;

            }
            ultraGrid1.DisplayLayout.Bands[0].Columns["时段"].Width = 80;
        }

        private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
        {
            InitColumnWidth();
            ClassUltraGridCommonSet.ultraGrid1_InitializeRowFilter(e);
            ClassUltraGridCommonSet.InitUltraWinGridRowNumSetting(e);
        }
        private void SearchResult()
        {
            this.pager1.CurrentPageIndex = 1;
            m_filter = "";
            int nIndex = this.ultraGrid1.ActiveRow.Index;
            List<object> lstO = this.ultraGrid1.DisplayLayout.Bands[0].ColumnFilters.All.ToList();

            string strColumnName;
            string strColumnValue;
            SearchCondition condition = new SearchCondition();
            foreach (object o in lstO)
            {
                ColumnFilter cf = (ColumnFilter)o;
                strColumnName = cf.Column.Key;
                strColumnValue = cf.FilterConditions.Count > 0 ? ((FilterCondition)cf.FilterConditions.All[0]).CompareValue.ToString() : "";
                if (strColumnValue != "")
                {
                    condition = condition.AddCondition(m_dicColAliasName2Name[strColumnName], strColumnValue, SqlOperator.Equal);
                }
            }

            m_filter = condition.BuildConditionSql();
            m_filter = m_filter.Replace("Where", "");
            ShowAllRecordInDataGridView(m_filter);
        }
        private void AddNewRow()
        {
            if (Frm_Main.CheckPerm(this.Text, "增加"))
            {
                UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
            }
            else
            {
                MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
        }
        private void ultraGrid1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                SearchResult();
            }
          
            if (e.KeyCode == Keys.Enter && e.Modifiers == Keys.Control)
            {

                if (!m_bInsertFlag)
                {
                    AddNewRow();
                    //UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
                    //  row.Cells[2] = DateTime.Parse("1900-01-01");
                }
            }
            switch (e.KeyCode)
            {

                case Keys.Up:
                    {
                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;

                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex > 0)
                            nIndex--;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.AboveCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Down:
                    {
                        string strTemp = this.ultraGrid1.ActiveCell.Column.Header.Caption;

                        int nColumnIndex = this.ultraGrid1.ActiveCell.Column.Index;
                        int nIndex = ultraGrid1.ActiveRow.Index;
                        if (nIndex < ultraGrid1.Rows.Count - 1)
                            nIndex++;
                        this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                          false);
                        this.ultraGrid1.PerformAction(UltraGridAction.BelowCell, false,
                          false);
                        e.Handled = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].IgnoreRowColActivation = true;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activation = Activation.AllowEdit;
                        ultraGrid1.Rows[nIndex].Cells[nColumnIndex].Activate();
                        this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                          false);
                        break;
                    }

                case Keys.Right:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.NextCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
                case Keys.Left:
                    this.ultraGrid1.PerformAction(UltraGridAction.ExitEditMode, false,
                      false);
                    this.ultraGrid1.PerformAction(UltraGridAction.PrevCellByTab, false,
                      false);
                    e.Handled = true;
                    this.ultraGrid1.PerformAction(UltraGridAction.EnterEditMode, false,
                      false);
                    break;
            }

        }
        private bool AddGoodsDetail(int nRowIndex)
        {

            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];

                TrainingDB.Model.CK_SchdDetail modelCK_SchdDetail = new TrainingDB.Model.CK_SchdDetail();

                modelCK_SchdDetail.CK_ClassPrdSchdTabID = 0;
                modelCK_SchdDetail.CK_SchoolTabID = Convert.ToInt32(CurrentUGR.Cells["校区名称"].Value.ToString(), 10);
                modelCK_SchdDetail.CK_TeacherTabID = Convert.ToInt32(CurrentUGR.Cells["讲师姓名"].Value.ToString());
                modelCK_SchdDetail.CK_ClassRoomExTabID = Convert.ToInt32(CurrentUGR.Cells["教室"].Value.ToString());
                modelCK_SchdDetail.CK_CourseTabID = Convert.ToInt32(CurrentUGR.Cells["课程名称"].Value.ToString());
                modelCK_SchdDetail.CK_ClassTabID = Convert.ToInt32(CurrentUGR.Cells["班级名称"].Value.ToString());
                modelCK_SchdDetail.CK_TimeSegTabID = Convert.ToInt32(CurrentUGR.Cells["时段"].Value.ToString());

                modelCK_SchdDetail.hourQtty = Convert.ToDecimal(CurrentUGR.Cells["课时数"].Value.ToString());
                modelCK_SchdDetail.hourFeeStd = Convert.ToDecimal(CurrentUGR.Cells["课时费标准"].Value.ToString());
                modelCK_SchdDetail.hourFee = Convert.ToDecimal(CurrentUGR.Cells["课时费"].Value.ToString());
                modelCK_SchdDetail.isStudy = Convert.ToBoolean(CurrentUGR.Cells["是否上课"].Value.ToString());
                modelCK_SchdDetail.objType = CurrentUGR.Cells["类型"].Value.ToString();

                modelCK_SchdDetail.classDate = Convert.ToDateTime(CurrentUGR.Cells["日期"].Value.ToString());


                int nId = m_bllCK_SchdDetail.Add(modelCK_SchdDetail);
                this.pager1.CurrentPageIndex = 1;
                ShowAllRecordInDataGridView("CK_SchdDetailid = '" + nId.ToString() + "'");
      //          MessageBox.Show("添加教室成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);

                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }
        private void InitNewAddRowValue(int nIndex)
        {
            UltraGridRow CurrentUGR = ultraGrid1.Rows[nIndex];

            CurrentUGR.Cells["校区名称"].Value = 1;
            CurrentUGR.Cells["讲师姓名"].Value = m_bllCK_TeacherTab.GetMaxId() - 1;
            CurrentUGR.Cells["课程名称"].Value = 1;
            CurrentUGR.Cells["教室"].Value = 1;
            CurrentUGR.Cells["班级名称"].Value = 1;
            CurrentUGR.Cells["时段"].Value = 1;

            CurrentUGR.Cells["类型"].Value = "";
            CurrentUGR.Cells["课时费标准"].Value = 0;
            CurrentUGR.Cells["课时数"].Value = 0;
            CurrentUGR.Cells["课时费"].Value = 0;
            CurrentUGR.Cells["是否上课"].Value = false;

            CurrentUGR.Cells["日期"].Value = System.DateTime.Now.Date;
     

            if (m_bInsertFlag)
            {
                ultraGrid1.Rows[nIndex].Cells[0].Activation = Activation.ActivateOnly;
                m_bInsertFlag = false;
                AddGoodsDetail(nIndex);

            }

        }

        private void ultraGrid1_AfterRowInsert(object sender, RowEventArgs e)
        {
            ultraGrid1.Rows[e.Row.Index].Cells[1].IgnoreRowColActivation = true;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activation = Activation.AllowEdit;
            ultraGrid1.Rows[e.Row.Index].Cells[1].Activate();
            ultraGrid1.PerformAction(UltraGridAction.EnterEditMode);
            m_bInsertFlag = true;
            InitNewAddRowValue(e.Row.Index);
        }

        private bool ModifyGoodsDetail(int nRowIndex)
        {

            try
            {
                if (!Frm_Main.CheckPerm(this.Text, "修改"))
                {
                    MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return false;
                }
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[nRowIndex];
                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(CurrentUGR.Cells[0].Value.ToString(), 10);
                TrainingDB.Model.CK_SchdDetail modelCK_SchdDetail = m_bllCK_SchdDetail.GetModel(nSelectFinRecvMoneyDetailTab_NewID);


                modelCK_SchdDetail.hourQtty = Convert.ToDecimal(CurrentUGR.Cells["课时数"].Value.ToString());
                modelCK_SchdDetail.hourFeeStd = Convert.ToDecimal(CurrentUGR.Cells["课时费标准"].Value.ToString());
                modelCK_SchdDetail.hourFee = Convert.ToDecimal(CurrentUGR.Cells["课时费"].Value.ToString());
                modelCK_SchdDetail.isStudy = Convert.ToBoolean(CurrentUGR.Cells["是否上课"].Value.ToString());
                modelCK_SchdDetail.objType = CurrentUGR.Cells["类型"].Value.ToString();

                modelCK_SchdDetail.classDate = Convert.ToDateTime(CurrentUGR.Cells["日期"].Value.ToString());


                string strBGH = CurrentUGR.Cells["校区名称"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_SchdDetail.CK_SchoolTabID = Convert.ToInt32(CurrentUGR.Cells["校区名称"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_SchoolTab.GetList("CK_SchoolTabName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_SchdDetail.CK_SchoolTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_SchoolTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["讲师姓名"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_SchdDetail.CK_TeacherTabID = Convert.ToInt32(CurrentUGR.Cells["讲师姓名"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_TeacherTab.GetList("CK_TeacherName = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_SchdDetail.CK_TeacherTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_TeacherTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["教室"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_SchdDetail.CK_ClassRoomExTabID = Convert.ToInt32(CurrentUGR.Cells["教室"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_ClassRoomExTab.GetList("CK_ClassRoomExEx = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_SchdDetail.CK_ClassRoomExTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_ClassRoomExTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["课程名称"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_SchdDetail.CK_CourseTabID = Convert.ToInt32(CurrentUGR.Cells["课程名称"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_CourseTab.GetList("CK_course = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_SchdDetail.CK_CourseTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_CourseTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["班级名称"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_SchdDetail.CK_ClassTabID = Convert.ToInt32(CurrentUGR.Cells["班级名称"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_ClassTab.GetList("CK_className = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_SchdDetail.CK_ClassTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_ClassTabID"].ToString(), 10);
                    }
                }

                strBGH = CurrentUGR.Cells["时段"].Value.ToString();
                if (ClassInputValid.IsNum(strBGH))
                {
                    modelCK_SchdDetail.CK_TimeSegTabID = Convert.ToInt32(CurrentUGR.Cells["时段"].Value.ToString(), 10);
                }
                else
                {
                    DataSet ds = m_bllCK_TimeSegTab.GetList("CK_ClassTime = '" + strBGH + "'");
                    if (ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                    {
                        modelCK_SchdDetail.CK_TimeSegTabID = Convert.ToInt32(ds.Tables[0].Rows[0]["CK_TimeSegTabID"].ToString(), 10);
                    }
                }



                m_bllCK_SchdDetail.Update(modelCK_SchdDetail);

               // MessageBox.Show("修改教室成功!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return true;

            }
            catch (System.Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return false;
            }
        }

        private void ultraGrid1_AfterCellActivate(object sender, EventArgs e)
        {
            int iIndex = this.ultraGrid1.ActiveCell.Row.Index;
            if (iIndex < 0)
                return;
            m_nDelIndex = ultraGrid1.ActiveRow.Index;
        }

        private void ultraGrid1_BeforeRowUpdate(object sender, CancelableRowEventArgs e)
        {
            try
            {
                UltraGridRow CurrentUGR;
                CurrentUGR = ultraGrid1.Rows[e.Row.Index];

                if (m_bInsertFlag)
                {
                    ultraGrid1.Rows[e.Row.Index].Cells[2].Activation = Activation.ActivateOnly;
                    m_bInsertFlag = false;
                    if (!AddGoodsDetail(e.Row.Index))
                        e.Cancel = true;
                }
                else//修改
                {

                    ModifyGoodsDetail(e.Row.Index);

                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void ultraGrid1_BeforeRowsDeleted(object sender, BeforeRowsDeletedEventArgs e)
        {
            e.DisplayPromptMsg = false;
            if (!m_bInsertFlag)
            {
                int nSelectFinRecvMoneyDetailTab_NewID = Convert.ToInt32(ultraGrid1.ActiveRow.Cells[0].Value.ToString(), 10);
                TrainingDB.Model.CK_SchdDetail modelCK_SchdDetailOld = m_bllCK_SchdDetail.GetModel(nSelectFinRecvMoneyDetailTab_NewID);

                if (modelCK_SchdDetailOld == null)
                {
                    MessageBox.Show("数据库不存在该记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                    return;
                }

                if (MessageBox.Show("确实要删除该条记录!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Information) == DialogResult.OK)
                {
                    try
                    {

                        m_bllCK_SchdDetail.Delete(nSelectFinRecvMoneyDetailTab_NewID);



                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show(ex.ToString(), "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        e.Cancel = true;
                    }
                }
                else
                {
                    e.Cancel = true;
                }
            }
            else
            {
                MessageBox.Show("插入未完成，不能删除记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                e.Cancel = true;
            }
        }

        private void 增加一行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!m_bInsertFlag)
            {
                AddNewRow();
                //UltraGridRow row = this.ultraGrid1.DisplayLayout.Bands[0].AddNew();
            }
        }

        private void 删除一行ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (!Frm_Main.CheckPerm(this.Text, "删除"))
            {
                MessageBox.Show("对不起您没有该权限!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
                return;
            }
            int nIndex = m_nDelIndex;
            if (m_nDelIndex >= 0)
            {
                DialogResult dr = MessageBox.Show("确实要删除该记录么!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
                if (dr == DialogResult.Cancel)
                {
                    return;
                }

                if (ultraGrid1.ActiveRow != null)
                {

                    ultraGrid1.ActiveRow.Delete(false);
                }
            }
            else
            {
                MessageBox.Show("请选中要删除的记录!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
            }
        }

        public string SqlValueList(string sql)
        {
            DataSet ds = DbHelperSQL.Query(sql.ToString());
            string strTotal = ds.Tables[0].Rows[0]["Total"].ToString();

            return strTotal;
        }

        /// <summary>    
        /// 执行SQL查询语句，返回所有记录的DataTable集合。    
        /// </summary>    
        /// <param name="sql">SQL查询语句</param>    
        /// <returns></returns>    
        public DataTable SqlTable(string sql)
        {
            DataSet ds = DbHelperSQL.Query(sql.ToString());
            return ds.Tables[0];
        }
 
        private DataTable FindToDataTable(string where, PagerInfo pagerInfo)
        {
            WHC.Pager.WinControl.PagerHelper helper = new WHC.Pager.WinControl.PagerHelper(@"select CK_SchdDetailId
,CK_ClassPrdSchdTab.CK_ClassPrdSchdNo
,CK_SchoolTab.CK_SchoolTabName       
,CK_TeacherTab.CK_TeacherName 
,CK_CourseTab.CK_course
,CK_ClassRoomExTab.CK_ClassRoomExEx
,CK_ClassTab.CK_className
,CK_TimeSegTab.CK_ClassTime
,CK_SchdDetail.classDate
,CK_SchdDetail.hourQtty
,CK_SchdDetail.hourFeeStd
,CK_SchdDetail.hourFee
,CK_SchdDetail.isStudy
,CK_SchdDetail.objType 
 from CK_SchdDetail
 join CK_SchoolTab on CK_SchoolTab.CK_SchoolTabid = CK_SchdDetail.CK_SchoolTabid 
join CK_TeacherTab on CK_TeacherTab.CK_TeacherTabID = CK_SchdDetail.CK_TeacherTabID
join CK_CourseTab on CK_CourseTab.CK_CourseTabID = CK_SchdDetail.CK_CourseTabID
join CK_ClassRoomExTab on CK_ClassRoomExTab.CK_ClassRoomExTabID = CK_SchdDetail.CK_ClassRoomExTabID 
join CK_ClassTab on CK_ClassTab.CK_ClassTabID = CK_SchdDetail.CK_ClassTabID
join CK_TimeSegTab on CK_TimeSegTab.CK_TimeSegTabID = CK_SchdDetail.CK_TimeSegTabID
left join CK_ClassPrdSchdTab on CK_ClassPrdSchdTab.CK_ClassPrdSchdTabid = CK_SchdDetail.CK_ClassPrdSchdTabid 
", "*", "CK_SchdDetailID", pagerInfo.PageSize, pagerInfo.CurrenetPageIndex, true, where);
            string countSql = helper.GetPagingSql(WHC.Pager.WinControl.DatabaseType.SqlServer, true);
            string dataSql = helper.GetPagingSql(WHC.Pager.WinControl.DatabaseType.SqlServer, false);

            string value = SqlValueList(countSql);
            pagerInfo.RecordCount = Convert.ToInt32(value);//为了显示具体的信息，需要设置总记录数
            DataTable dt = SqlTable(dataSql);
            this.pager1.InitPageInfo(pagerInfo.RecordCount, pagerInfo.PageSize);
            return dt;
        }

        private void BindData(string strWhere)
        {
            this.ultraGrid1.DataSource = null;
            DataTable dt = FindToDataTable(strWhere, this.pager1.PagerInfo);

            DataSet dsTemp = m_bllCK_SchoolTab.GetOnlyList("");

            this.ultraDropDownDep.DataSource = dsTemp.Tables[0];
            this.ultraDropDownDep.DisplayMember = "校区名称";
            this.ultraDropDownDep.ValueMember = "CK_SchoolTabID";
            this.ultraDropDownDep.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownDep.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownDep.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownDep.DisplayLayout.Bands[0].Columns["校区名称"].Hidden = false;

            dsTemp = m_bllCK_TeacherTab.GetOnlyList("");

            this.ultraDropDownT1.DataSource = dsTemp.Tables[0];
            this.ultraDropDownT1.DisplayMember = "教师名称";
            this.ultraDropDownT1.ValueMember = "CK_TeacherTabID";
            this.ultraDropDownT1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownT1.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownT1.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownT1.DisplayLayout.Bands[0].Columns["教师名称"].Hidden = false;

            dsTemp = m_bllCK_CourseTab.GetOnlyList("");

            this.ultraDropDownCourse.DataSource = dsTemp.Tables[0];
            this.ultraDropDownCourse.DisplayMember = "课程名称";
            this.ultraDropDownCourse.ValueMember = "CK_CourseTabID";
            this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownCourse.DisplayLayout.Bands[0].Columns["课程名称"].Hidden = false;

            dsTemp = m_bllCK_ClassRoomExTab.GetList("");

            this.ultraDropDownClassRoom.DataSource = dsTemp.Tables[0];
            this.ultraDropDownClassRoom.DisplayMember = "CK_ClassRoomExEx";
            this.ultraDropDownClassRoom.ValueMember = "CK_ClassRoomExTabID";
            this.ultraDropDownClassRoom.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownClassRoom.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownClassRoom.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownClassRoom.DisplayLayout.Bands[0].Columns["CK_ClassRoomExEx"].Hidden = false;

            dsTemp = m_bllCK_ClassTab.GetList("");

            this.ultraDropDownClass.DataSource = dsTemp.Tables[0];
            this.ultraDropDownClass.DisplayMember = "CK_className";
            this.ultraDropDownClass.ValueMember = "CK_ClassTabID";
            this.ultraDropDownClass.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownClass.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownClass.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownClass.DisplayLayout.Bands[0].Columns["CK_className"].Hidden = false;

            dsTemp = m_bllCK_TimeSegTab.GetList("");

            this.ultraDropDownTimeSeg.DataSource = dsTemp.Tables[0];
            this.ultraDropDownTimeSeg.DisplayMember = "CK_ClassTime";
            this.ultraDropDownTimeSeg.ValueMember = "CK_TimeSegTabID";
            this.ultraDropDownTimeSeg.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            for (int i = 0; i < this.ultraDropDownTimeSeg.DisplayLayout.Bands[0].Columns.Count; i++)
                this.ultraDropDownTimeSeg.DisplayLayout.Bands[0].Columns[i].Hidden = true;
            this.ultraDropDownTimeSeg.DisplayLayout.Bands[0].Columns["CK_ClassTime"].Hidden = false;




            //DataSet ds = m_bllCK_SchdDetail.GetList(strWhere);
            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                dt.Columns[strTemp].ColumnName = m_dicColName2AliasName[strTemp];

            }
            this.ultraGrid1.DataSource = dt;

            this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Hidden = true;
            //this.ultraGrid1.DisplayLayout.Bands[0].Columns[1].Hidden = true;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["校区名称"].ValueList = this.ultraDropDownDep;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["讲师姓名"].ValueList = this.ultraDropDownT1;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["课程名称"].ValueList = this.ultraDropDownCourse;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["班级名称"].ValueList = this.ultraDropDownClass;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["教室"].ValueList = this.ultraDropDownClassRoom;
            this.ultraGrid1.DisplayLayout.Bands[0].Columns["时段"].ValueList = this.ultraDropDownTimeSeg;
   
        }

        void pager1_PageChanged(object sender, EventArgs e)
        {
            BindData(m_filter);
        }

        void pager1_ExportCurrent(object sender, EventArgs e)
        {
            DataTable dt = (DataTable)ultraGrid1.DataSource;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGridExcelExporter1.Export(ultraGrid1, outFile);
                }
            }
            MessageUtil.ShowTips("导出当前页记录成功");
        }

        void pager1_ExportAll(object sender, EventArgs e)
        {
            DataSet ds = m_bllCK_SchdDetail.GetAllList("");
            DataTable dt = ds.Tables[0];
            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                dt.Columns[strTemp].ColumnName = m_dicColName2AliasName[strTemp];

            }
            ultraGrid2.DataSource = dt;

            if (dt != null)
            {
                if (dt.Rows.Count > 0)
                {
                    SaveFileDialog sfd = new SaveFileDialog();
                    sfd.Filter = "Excel文件(*.xls)|*.xls";
                    string outFile = "";

                    if (sfd.ShowDialog() == DialogResult.OK)
                    {
                        outFile = sfd.FileName;
                    }
                    else
                    {
                        return;
                    }

                    ultraGridExcelExporter1.Export(ultraGrid2, outFile);
                }
            }
            MessageUtil.ShowTips("导出所有记录成功");
        }      
  
        private void Frm_ClassRoom_Load_1(object sender, EventArgs e)
        {
            this.pager1.PageChanged += new WHC.Pager.WinControl.PageChangedEventHandler(pager1_PageChanged);
            this.pager1.ExportCurrent += new WHC.Pager.WinControl.ExportCurrentEventHandler(pager1_ExportCurrent);
            this.pager1.ExportAll += new WHC.Pager.WinControl.ExportAllEventHandler(pager1_ExportAll);

            ClassUltraGridCommonSet.InitUltraWinGridSetting(this.ultraGrid1);
            m_dicColName2AliasName.Add("CK_SchoolTabName", "校区名称");
            m_dicColName2AliasName.Add("CK_TeacherName", "讲师姓名");
            m_dicColName2AliasName.Add("CK_course", "课程名称");
            m_dicColName2AliasName.Add("CK_ClassRoomExEx", "教室");
            m_dicColName2AliasName.Add("CK_className", "班级名称");
            m_dicColName2AliasName.Add("CK_ClassTime", "时段");


            m_dicColName2AliasName.Add("CK_ClassPrdSchdNo", "排课编号");
            m_dicColName2AliasName.Add("classDate", "日期");
            m_dicColName2AliasName.Add("hourQtty", "课时数");
            m_dicColName2AliasName.Add("hourFeeStd", "课时费标准");
            m_dicColName2AliasName.Add("hourFee", "课时费");


            m_dicColName2AliasName.Add("isStudy", "是否上课");
            m_dicColName2AliasName.Add("objType", "类型");


            foreach (string strTemp in m_dicColName2AliasName.Keys)
            {
                m_dicColAliasName2Name.Add(m_dicColName2AliasName[strTemp], strTemp);
            }
        }

        private void pager1_Load(object sender, EventArgs e)
        {

        }

    }
}

